package com.service;

import java.util.LinkedList;
import java.util.List;

import com.dao.ProductDAO;
import com.domain.Product;

public class ProductService {
	public int insertProduct(Product product) {
		ProductDAO dao = new ProductDAO();
		return dao.insert(product);
	}

	public List<Product> getAllProduct() {
		List<Product> list = new LinkedList<Product>();
		ProductDAO dao = new ProductDAO();
		return dao.getAllProduct();
	}

	public Product getProductById(int code) {
		ProductDAO dao = new ProductDAO();
		return dao.getProductById(code);
	}

	public int deleteProductById(int code) {
		ProductDAO dao = new ProductDAO();
		Product product = getProductById(code);
		if (product != null) {
			dao.deleteProduct(product);
			return 1;
		}
		else {
			return 0;
		}
	}
}
